Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | 'use strict'; |
||
8 | describe(`${pkg.name}/Lexer/Input`, () => { |
||
9 | /** @test {Input#constructor} */ |
||
10 | describe('#constructor', () => { |
||
11 | it('Create a new instance of type Input', () => { |
||
12 | assert.instanceOf(new Input(''), Input); |
||
13 | }); |
||
14 | }); |
||
15 | |||
16 | /** @test {Input#eof} */ |
||
17 | describe('#eof', () => { |
||
18 | it('Determine whether or not there are no more values in the stream.', () => { |
||
19 | const stream = new Input(''); |
||
20 | assert.isTrue(stream.eof()); |
||
21 | }); |
||
22 | }); |
||
23 | |||
24 | /** @test {Input#error} */ |
||
25 | describe('#error', () => { |
||
26 | it('Throw a new Error.', () => { |
||
27 | const stream = new Input(''); |
||
28 | |||
29 | assert.throws(() => { |
||
30 | stream.error('Parse error'); |
||
31 | }, Error, 'Parse error (Line: 1, Column: 0)'); |
||
32 | }); |
||
33 | }); |
||
34 | |||
35 | /** @test {Input#next} */ |
||
36 | describe('#next', () => { |
||
37 | it('Return the next value from the stream.', () => { |
||
38 | const stream = new Input('> hello botlang'); |
||
39 | |||
40 | assert.strictEqual(stream.next(), ' '); |
||
41 | assert.strictEqual(stream.next(), 'h'); |
||
42 | assert.strictEqual(stream.next(), 'e'); |
||
43 | assert.strictEqual(stream.next(), 'l'); |
||
44 | assert.strictEqual(stream.next(), 'l'); |
||
45 | assert.strictEqual(stream.next(), 'o'); |
||
46 | assert.strictEqual(stream.next(), ' '); |
||
47 | assert.strictEqual(stream.next(), 'b'); |
||
48 | assert.strictEqual(stream.next(), 'o'); |
||
49 | assert.strictEqual(stream.next(), 't'); |
||
50 | assert.strictEqual(stream.next(), 'l'); |
||
51 | assert.strictEqual(stream.next(), 'a'); |
||
52 | assert.strictEqual(stream.next(), 'n'); |
||
53 | assert.strictEqual(stream.next(), 'g'); |
||
54 | }); |
||
55 | }); |
||
56 | |||
57 | /** @test {Input#peek} */ |
||
58 | describe('#peek', () => { |
||
59 | it('Return the value from the current position.', () => { |
||
60 | const stream = new Input('> hello botlang'); |
||
61 | |||
62 | assert.strictEqual(stream.peek(), '>'); |
||
63 | }); |
||
64 | }); |
||
65 | }); |
||
66 |